package ind.nuts.lang.entity;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.Serializable;

/**
 * @author haoyun.zheng
 */
@Data
@AllArgsConstructor
public class ResponseData<T> implements Serializable {

    private static final long serialVersionUID = -1563765689754678056L;

    private static final int OK = 20000;
    private static final int ERROR = 50000;

    private Integer code;
    private String message;
    private T data;

    public static <T> ResponseData<T> ok() {
        return new ResponseData<>(OK, null, null);
    }

    public static <T> ResponseData<T> ok(String message) {
        return new ResponseData<>(OK, message, null);
    }

    public static <T> ResponseData<T> ok(T data) {
        return new ResponseData<>(OK, null, data);
    }

    public static <T> ResponseData<T> ok(String message, T data) {
        return new ResponseData<>(OK, message, data);
    }

    public static <T> ResponseData<T> error() {
        return new ResponseData<>(ERROR, null, null);
    }

    public static <T> ResponseData<T> error(String message) {
        return new ResponseData<>(ERROR, message, null);
    }

    public static <T> ResponseData<T> error(T data) {
        return new ResponseData<>(ERROR, null, data);
    }

    public static <T> ResponseData<T> error(String message, T data) {
        return new ResponseData<>(ERROR, message, data);
    }
}

